cmake_minimum_required(VERSION 3.10)

#设置编译debug和release开关
#SET(CMAKE_BUILD_TYPE "Debug")
#SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -o0 -Wall -g2 -ggdb")
#SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -o3 -Wall")

#set the project name
project(ISO8583Tools VERSION 1.0)

#specify the c++ standard, 声明支持c++ 11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

#编译工程添加生成配置选项,此处设置该选项默认为开
#option(USE_MYMATH "Use tutorial provided math implementaion" ON)

#control where the static and shared libraries are built so that on windows
#we don`t need to thinker with the path to run the executable
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

#pass the verion info to source code by TutorialConfig.h generated by cmake
#cmake执行期间根据TutorialConfig.h.in自动生成TutorialConfig.h,头文件中包含主版本号和子版本号的宏定义
#文件在生成目录中生成，所以后面需要包含的头文件目录中添加生成目录，以便在工程源码中引用头文件TuroialConfig.h中的版本信息
configure_file(ISO8583ToolsConfig.h.in ISO8583ToolsConfig.h)

#判定编译选项USE_MYMATH是否打开，为ON即满足条件
#if(USE_MYMATH)
    #add the MathFunctions library
    #添加库文件目录
    add_subdirectory(ISO8583)
    #list append操作，想EXTRA_LIBS中添加MathFunctions
    list(APPEND EXTRA_LIBS ISO8583)
    #list append操作，向EXTRA_INCLUDES添加一条路径
    #list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
#endif()

#add the executable
#声明生成的可执行文件名称及对应源文件
add_executable(ISO8583Tools
                ISO8583CustomPay.cpp
                ISO8583Tools.cpp)

#指明要使用的库文件
target_link_libraries(ISO8583Tools PUBLIC ${EXTRA_LIBS})

#PROJECT_BINARY_DIR是执行cmake指令生成二进制文件的目录位置
#PROJECT_SOURCE_DIR是顶层CMakeLists.txt文件所在的目录位置，即工程的根目录
target_include_directories(ISO8583Tools PUBLIC
                            "${PROJECT_BINARY_DIR}"
                            # ${EXTRA_INCLUDES}
                            )

# 安装规则
install(TARGETS ISO8583Tools DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
    DESTINATION include
    )
